package test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import Beans.Artigiano;
import businessLogic.GestioneArtigianiMySQL;

import connessioni.MyConnection;
import db_operations.GestioneArtigiani;

public class GetArtigiano_Test1 {
	
	public static void main(String args[]) throws Exception {
		
		try {
			Connection con = MyConnection.getConnection();
			
			Statement st = con.createStatement();
			
			
			ResultSet n = st.executeQuery("SELECT MAX(ID) FROM artigiani");
			if(!n.next())
				throw new Exception("Nessun artigiano nel DB");
			
			int id = n.getInt(1);
			
			GestioneArtigiani ga = new GestioneArtigianiMySQL();
			Artigiano a = ga.getArtigiano(id);
			
			visualizza(a);
			
		}
		catch(SQLException e) {
			e.printStackTrace();
		}	
		
		catch(ClassNotFoundException ex) {
			ex.printStackTrace();
		}
	}
	
	
	private static void visualizza(Artigiano a) {
		System.out.println("ID: " + a.getId());
		System.out.println("Nome: " + a.getNome());
		System.out.println("Cognome: " + a.getCognome());
		System.out.println("PIva: " + a.getPIva());
		System.out.println("Email: " + a.getEmail());
		System.out.println("IDPartner: " + a.getPartner().getID());
		System.out.println("TipoArtigiano: " + a.getTipoArtigiano().getId());
		System.out.println("Nazione: " + a.getNazione());
		System.out.println("Regione: " + a.getRegione());
		System.out.println("Città: " + a.getCitta());
		System.out.println("Provincia: " + a.getProvincia());
		System.out.println("CAP: " + a.getCap());
		System.out.println("Via: " + a.getVia());
		System.out.println("NCivico: " + a.getNCivico());
		System.out.println("PathImg: " + a.getPathImg());
		System.out.println("Note: " + a.getNote());
		
		for(int i = 0; i < a.getTelefono().length; i++)
			System.out.println("Tel " + i + " : " + a.getTelefono()[i]);
		
		for(int i = 0; i < a.getFax().length; i++)
			System.out.println("Fax " + i + " : " + a.getFax()[i]);
	}

}
